const { Sequelize } = require("sequelize");
const {
  MYSQL_HOST,
  MYSQL_PORT,
  MYSQL_USER,
  MYSQL_PWD,
  MYSQL_DB,
} = require("../config/config.default");

const seq = new Sequelize(MYSQL_DB, MYSQL_USER, MYSQL_PWD, {
  // 主机地址
  host: MYSQL_HOST,
  port: MYSQL_PORT,
  // 数据库类型
  dialect:
    "mysql" /* one of 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'db2' | 'snowflake' | 'oracle' */,
  // ncc打包需要
  dialectModule: require("mysql2"),
});

seq
  .authenticate()
  .then(() => console.log("数据库连接成功", MYSQL_HOST))
  .catch((err) => console.log("数据量连接失败", MYSQL_HOST, err));

module.exports = seq;
